#{extends '/include/main_include.html'/}

<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=places&sensor=true"></script>

<script type="text/javascript">
//<!--
var map;
/**************************************
 * Document Ready
 **************************************/
$(document).ready(function(){
	/***************************************
	 * 페이지 호출시 글쓰기 폼은 숨겨놓는다.
	 ***************************************/
	$("#post_feed").hide();
	
	/**********************
	 * 글 작성 버튼 선택
	 **********************/
	$("#write_feed").click(function(){
		$("#post_feed").show();
		
		/********************
		 * 구글맵 초기화
		 ********************/
		var initialLocation;
		var latlng = new google.maps.LatLng(-34.397, 150.644);
		var options = {
			zoom		:	8,
			center		:	latlng,
			mapTypeId	:	google.maps.MapTypeId.ROADMAP
		};
		
		map = new google.maps.Map(document.getElementById("lm-map-canvas"), options);
		
		if(navigator.geolocation) {
			console.debug("위치정보 지원");
			var browserSupportFlag = true;
			navigator.geolocation.getCurrentPosition(function(position) {
				console.debug("getCurrentPosition Success");
				initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
				map.setCenter(initialLocation);
		    }, function() {
		    	console.debug("getCurrentPosition Fail");
		    });
		} else {
			console.debug("위치정보 미지원");
		} // if
		
	}); // post_feed
	
	/***********************
	 * 글 작성 제출
	 ***********************/
	$("#post-submit").click(function(){
		$.post('/post', '', function(result){
			// Post Callback
		});
	}); // post-submit()
	
	/**************
	 * 위치검색
	 **************/
	$("#lm-postfeed-search-map").keydown(function(event){
		if (event.keyCode == 13) {
			console.debug("Press Enter");
			// TODO : 검색시작
			var search = $(this).val();
				
			// 구글 API 를 이용하여 검색한다.
			
			// 검색할 주소 목록을 생성
			var searchList = lm.googleMap.search.createAddressList(search);
			
			// 검색할 주소 번호
			var searchNo = 0;
			
			lm.googleMap.search.geocode(searchList, searchNo, function(result){
				
			});
			/*
			// 지오코드 검색
			var geocoder = new google.maps.Geocoder();
			if (geocoder) {
				geocoder.geocode({address : search}, function(result, status){
					if (status == google.maps.GeocoderStatus.OK) {
						console.debug("Location : " + result[0].geometry.location);
						map.setCenter(result[0].geometry.location);
					} else {
						console.debug("error : " + status);
					}
				});
			} // if
			
			// 위치검색
			var placeRequest = {
				bounds : map.getBounds(),
				keyword : search,
				types: ['store']
			};
			var placesService = new google.maps.places.PlacesService(map);
			placesService.search(placeRequest, function(results, status){
				console.debug("Place Count : " + results.length);
				for (var i = 0; i < results.length; i++) {
					var place = results[i];
					console.debug("Name : " + place.name);
				} // for
			});
			*/
		} // if
	}); // 위치 검색
}); // document.ready()
</script>

<div class="lm-header">
	<div class="lm-title">
		LetzMeet
	</div>
	<div class="lm-user">
		<img src="https://graph.facebook.com/${facebook_id}/picture" width="30px" height="30px"/>
		${name}
	</div>
</div>

<div class="lm-body">
	<!-- Body Start -->
	<a href="#" id="write_feed">Write Feed</a>
	<!-- Body End -->

	<!-- Write Post Start -->
	<div id="post_feed" class="lm-post-layer">
		<textarea id="feed" class="lm-post-textarea"></textarea>
		<p>
			<label>
				<input type="checkbox"/>
				<span>위치정보</span>
			</label>
			<label>
				<span>검색</span>
				<input type="text" id="lm-postfeed-search-map" class="lm-postfeed-search-map"/>
			</label>
			<div id="lm-map-canvas" class="lm-map-canvas"></div>
		</p>
		<a href="#" id="post-submit">Post</a>
		
		<!-- 위치검색 목록 시작 -->
		<div id="lm-searchmap-list" class="lm-searchmap-list">
			<ul>
				<li></li>
			</ul>
		</div>
		<!-- 위치검색 목록 종료 -->
	</div>
	<!-- Write Post End -->
	
</div>
